<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>
    <link th:href="@{/css/common.css}" rel="stylesheet"/>
</head>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form" lay-filter="searchForm">
                <div class="layui-form-item layui-form-pane">
                    <label class="layui-form-label" for="username">姓名</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="username" name="username" autocomplete="off"
                               placeholder="请输入姓名">
                    </div>
                    <label class="layui-form-label" for="idCard">身份证</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="idCard" name="idCard" autocomplete="off"
                               placeholder="请输入身份证">
                    </div>
                    <label class="layui-form-label" for="college">学院</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="college" name="college" autocomplete="off"
                               placeholder="请输入学院">
                    </div>
                    <label class="layui-form-label" for="major">专业</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="major" name="major" autocomplete="off"
                               placeholder="请输入学院">
                    </div>
                </div>
                <div class="layui-form-item layui-form-pane">
                    <label class="layui-form-label" for="grade">年级</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="grade" name="grade" autocomplete="off"
                               placeholder="请输入年级">
                    </div>
                    <label class="layui-form-label" for="classNo">班级</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="classNo" name="classNo" autocomplete="off"
                               placeholder="请输入班级">
                    </div>
                    <label class="layui-form-label" for="type">致贫类型</label>
                    <div class="layui-input-inline">
                        <select id="type" name="type">
                            <option value="">请选择类型</option>
                            <option value="1">因病致贫</option>
                            <option value="2">因灾致贫</option>
                            <option value="3">低保</option>
                            <option value="4">农村低收入子女</option>
                            <option value="5">特困子女</option>
                            <option value="6">烈士子女</option>
                            <option value="7">少数民族家庭经济困难子女</option>
                        </select>
                    </div>
                    <label class="layui-form-label" for="resultRank">贫困等级</label>
                    <div class="layui-input-inline">
                        <select class="layui-input" id="resultRank" name="resultRank">
                            <option value="">请选择贫困等级</option>
                            <option value="1">不贫困</option>
                            <option value="2">一般贫困</option>
                            <option value="3">特别贫困</option>
                        </select>
                    </div>
                </div>
                    <label class="layui-form-label" for="status">审核状态</label>
                    <div class="layui-input-inline">
                        <select class="layui-input" id="status" name="status">
                            <option value="">请选择审核状态</option>
                            <option value="3">审核通过</option>
                            <option value="2">审核不通过</option>
                            <option value="1">审核中</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <button class="layui-btn layui-btn-radius layui-btn-normal" lay-submit lay-filter="searchBtn"
                                id="searchBtn">
                            <i class="layui-icon layui-icon-search"></i>查询
                        </button>
                        <button class="layui-btn layui-btn-radius layui-btn-primary" lay-submit lay-filter="resetBtn">
                            <i class="layui-icon layui-icon-refresh"></i>重置
                        </button>
                    </div>
                </div>
            </div>
            <table class="layui-table" id="dataTable" lay-filter="dataTable"></table>

            <script type="text/html" id="toolbar">
                <button class="layui-btn layui-btn-xs layui-btn-text" lay-event="evidences">
                    <i class="layui-icon layui-icon-edit">查看证明材料</i>
                </button>
                <button class="layui-btn layui-btn-xs layui-btn-text" lay-event="examine">
                    <i class="layui-icon layui-icon-edit">审批</i>
                </button>
            </script>
        </div>
    </div>
</div>
<div class="layui-form" style="display: none" id="dataForm" lay-filter="dataForm">
    <div class="layui-form-item">
        <input name="id" type="hidden">
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" for="resultRank1">贫困等级</label>
        <div class="layui-input-block">
            <select class="layui-input" id="resultRank1" name="resultRank">
                <option value="1">不贫困</option>
                <option value="2">一般贫困</option>
                <option value="3">特别贫困</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <button lay-submit lay-filter="saveBtn" id="saveBtn"></button>
        <button lay-submit lay-filter="updateBtn" id="updateBtn"></button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/layui/layui.js}"></script>
<script th:inline="none">
    var loanId = 0;
    layui.use(["table", "form","upload"], () => {
        const table = layui.table, form = layui.form,laydate = layui.laydate, $ = layui.$;

        const cols = [[
            {type: "numbers"},
            {title: "姓名", field: "username",width: 100,align: 'center'},
            {title: "性别", field: "gender",width: 80,align: 'center'},
            {title: "电话号码", field: "phone",width: 150,align: 'center'},
            {title: "身份证", field: "idCard",width: 200,align:'center'},
            {title: "学院", field: "college",width: 200,align:'center'},
            {title: "专业", field: "major",width: 150,align: "center"},
            {title: "年级", field: "grade",width: 100,align: 'center'},
            {title: "班级", field: "classNo",width: 100,align: 'center'},
            {title: "贫困类型", field: "type",width: 150,align: "center",templet:function(d){
                    if(d.type == 1) {
                        return "因病致贫";
                    }else if(d.type == 2) {
                        return "因灾致贫";
                    }else if(d.type == 3) {
                        return "低保";
                    }else if(d.type == 4) {
                        return "农村低收入子女";
                    }else if(d.type == 5) {
                        return "特困子女";
                    }else if(d.type == 6) {
                        return "烈士子女";
                    }else if(d.type == 7) {
                        return "少数民族家庭经济困难子女";
                    }
                }},
            {title: "申请理由", field: "reasons",width: 150,align: "center"},
            {title: "申请年度", field: "year",width: 100,align: 'center'},
            {title: "贫困等级", field: "resultRank",width: 100,align: 'center'},
            {title: "审核状态", field: "status",width: 100,align: 'center',style:'color:red;'},
            {title: "审核时间", field: "adminTime",width: 180,align: "center"},
            {title: "创建时间", field: "createTime",width: 180,align: "center"},
            {title: "修改时间", field: "updateTime",width: 180,align: "center"},
            {title: "操作栏", toolbar: "#toolbar", fixed: "right",width: 200,align: "center"}
        ]];

        const dataTable = table.render({
            elem: "#dataTable",
            height: "600px",
            toolbar: "#tableBar",
            id: "dataTable",
            page: {
                layout:['limit','count','prev','page','next','skip'],
                curr: 1,
                limit: 20
            },
            limit:[5,10,20,30,40,50],
            url: ctx + "loan/poor_apply/getPoorApplyList",
            parseData: ({code, data, msg}) => {
                const {list, total} = data;
                return {
                    "code": code,
                    "msg": msg,
                    "count": total,
                    "data": list
                }
            },
            cols: cols
        });

        form.on("submit(searchBtn)", data => {
            dataTable.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            })
        })

        form.on("submit(resetBtn)", data => {
            form.val("searchForm", {
                username: "",
                idCard: "",
                college: "",
                major: "",
                grade: "",
                classNo: "",
                type: "",
                resultRank: "",
            })
            $("#searchBtn").click();
        })



        table.on("tool(dataTable)", (obj) => {
            const {event, data, tr} = obj;
            loanId = data.id;
            switch (event) {
                case "examine":
                    form.val("dataForm", data);
                    openExamineForm(() => {
                        $("#updateBtn").click();
                    });
                    break;
                case "evidences":
                    form.val("dataForm", data);
                    openEvidencesPage(() => {
                        // $("#updateBtn").click();
                    });
                    break;
            }
        })

        const openExamineForm = resolve => {
            layer.open({
                type: 1,
                content: $("#dataForm"),
                area: ["300px", "400px"],
                btn: ["确定", "取消"],
                btnAlign: "c",
                yes: resolve
            })
        }

        const openEvidencesPage = resolve => {
            // console.log(window.location.href)
            layer.open({
                type: 2,
                content: './poor_apply/evidences?loanId='+loanId,
                area: ["600px", "700px"],
                title: "证明材料",
                btn: ["确定", "取消"],
                btnAlign: "c",
                yes: resolve
            })
        }

        form.on("submit(updateBtn)", data => {
            examined(data);
        })

        const examined = (data) => {
            const url = "loan/poor_apply/updateApply?id=" + data.field.id
            $.ajax({
                url: ctx + url,
                method: "post",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(data.field),
                success: ({code, msg}) => {
                    if (code !== 0) {
                        return layer.msg(msg, {icon: 5})
                    }
                    dataTable.reload();
                    layer.closeAll();
                }
            })
        }
    });
</script>
</body>
</html>